//
//  TenderWuliuCell.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2021/8/10.
//  Copyright © 2021 aowang. All rights reserved.
//

import UIKit

import Kingfisher
class TenderWuliuCell: TenderBaseCell {
    
    lazy var cheImg:UIImageView = {
        let  v = UIImageView(image: UIImage(named:"wl_che"))
        v.contentMode = .scaleAspectFit
        return v
    }()
    
    lazy var houChe:UILabel = {
        let v = UILabel()
        v.textColor = .lightGray
        v.font = UIFont.systemFont(ofSize: 14)
        v.numberOfLines = 2
        return v
    }()
    lazy var timeRange:UILabel = {
        let v = UILabel()
        v.textColor = .lightGray
        v.font = UIFont.systemFont(ofSize: 14)
        v.numberOfLines = 2
        return v
    }()
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.contentView.addSubview(cheImg)
        self.contentView.addSubview(houChe)
        self.contentView.addSubview(timeRange)
        
    }
    
    func makeConstrainsts() {
        
        dingwei.isHidden = false
        btn1.snp.makeConstraints { (make) in
            make.left.equalTo(lab1)
            make.width.equalTo(60)
            make.height.equalTo(25)
            make.top.equalTo(lab1)
        }
        lab1.snp.makeConstraints { (make) in
            make.left.equalTo(self.contentView).offset(11)
            make.right.equalTo(self.contentView).offset(-15)
            make.top.equalTo(self.contentView).offset(6)
        }
        
        lab2.snp.makeConstraints { (make) in
            make.left.right.equalTo(lab1)
            make.top.equalTo(lab1.snp.bottom).offset(6)
        }
        
        dingwei.snp.makeConstraints { (make) in
            make.height.equalTo(15)
            make.width.equalTo(14)
            make.left.equalTo(lab1)
            make.top.equalTo(lab2.snp.bottom).offset(6)
        }
        
        lab3.snp.makeConstraints { (make) in
            make.left.equalTo(lab1)
            make.top.equalTo(dingwei)
        }
        
        cheImg.snp.makeConstraints { (make) in
            make.left.equalTo(lab3.snp.right).offset(5)
            make.width.equalTo(28)
            make.height.equalTo(23)
            make.centerY.equalTo(lab3)
        }
        houChe.snp.makeConstraints { make in
            make.left.equalTo(cheImg.snp.right).offset(5)
            make.centerY.equalTo(lab3)
        }
        timeRange.snp.makeConstraints { (make) in
            make.left.equalTo(lab1)
            make.top.equalTo(lab3.snp.bottom).offset(5)
        }
        lab4.snp.makeConstraints { (make) in
            make.left.equalTo(lab1)
            make.right.equalTo(oper_btn.snp.left).offset(-2)
              make.bottom.equalTo(self.contentView).offset(-5)
        }
        
        oper_btn.snp.makeConstraints { (make) in
            make.top.equalTo(lab3.snp.bottom).offset(10)
            make.width.equalTo(70)
            make.right.equalTo(self.contentView).offset(-15)
            make.height.equalTo(32)
            make.bottom.equalTo(self.contentView).offset(-5)
            
        }
        
        
        
    }
    
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    var one = ZtbContentModel(JSON:["":""])! {
        didSet {
            
            lab1.attributedText = NSAttributedString(string: "                \(one.zTitle.unwrap)", attributes: titleAttributes)
            lab2.text = one.zTitle.unwrap
            lab3.text = "    \(one.sendCity.unwrap)"
            houChe.text = "\(one.zCity.unwrap)     \(categoryDicDesc[one.zDtradeType.unwrap].unwrap)"
            timeRange.text = "\(one.zBeginDate.unwrap)至\(one.zEndDate.unwrap)"
            
            let real_status = one.zStatus.isSome ? intTran(one.zStatus) : intTran(one.zZbStatus)
            btn1.setZBJPStatus(listType:.TB,auditmark: intTran(one.zAuditMark), status: real_status,tbType: one.innerType!)
            
            let re = self.helper.setBtnTitle(listType: one.innerType!, zAuditMark: one.zAuditMark.unwrap, btn2: oper_btn)
            
            if re.isEmpty {
                oper_btn.snp.remakeConstraints { (make) in
                    make.centerY.equalTo(dingwei)
                    make.width.equalTo(32)
                    make.right.equalTo(self.contentView).offset(-15)
                    make.height.equalTo(32)
                    make.bottom.equalTo(self.contentView).offset(-40)
                }
            }
            oper_btn.addTarget(self, action: #selector(btn2Action(sender:)), for: .touchUpInside)
            lab4.text = one.zPriceRank.unwrap
            
            
            
        }
    }
    @objc func btn2Action(sender:UIButton) {
        if let closure = btn2Closure {
            closure(sender,sender.titleLabel!.text.unwrap)
        }
    }
    
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
}
